from abc import ABC
from src.utils import log
from src.actions.base_action import Advance, Sleep
from src.actions.base_action import SpinAntiClockwise, Stop, SpinClockwise, CustomAction, ShiftLeft, TurnRight
class ComplexAction(ABC):
    def __init__(self, ):
        # 当前动作是否强制执行，默认为强制执行
        self.force = True
        # 当前动作序列是否更新控制器记录的速度，默认为不更新
        self.update_controller_speed = False
        pass


class Start(ComplexAction):
    def __init__(self):
        super().__init__()
        self.update_controller_speed = True
        self.action_seq = [
            Advance(speed=22),
            Sleep(0.2),
            Advance(speed=22)
        ]


class TurnLeftInPlace(ComplexAction):
    def __init__(self):
        super().__init__()
        self.action_seq = [
            Advance(speed=30),
            Sleep(1),
            SpinAntiClockwise(speed=30),
            Sleep(1),
            Stop()
        ]


class TurnRightInPlace(ComplexAction):
    def __init__(self):
        super().__init__()
        self.action_seq = [
            Advance(speed=30),
            Sleep(0.3),
            #SpinAntiClockwise(speed=30),
            SpinClockwise(speed=30),
            Sleep(0.9),
            Stop(),
            Advance(speed=30),  # 再次前进（速度35，持续2.3秒）
            Sleep(0.1),
        ]
        '''
        self.action_seq = [
            Advance(speed=23),
            Sleep(2.5),
            SpinClockwise(speed=30),
            Sleep(1),
            Advance(speed=30),
            Sleep(1),
            Stop()
        ]
        '''

class TurnAround(ComplexAction):
    def __init__(self):
        super().__init__()
        self.action_seq = [
            Stop(),
            Sleep(0.1),
            Advance(speed=35),  # 前进（速度35，持续2秒）
            Sleep(1.3),
            Stop(),
            Sleep(0.3),
            SpinAntiClockwise(speed=30),  # 降低旋转速度（如25）
            Sleep(1),  # 增加旋转时间以补偿低速
            Advance(speed=30),  # 再次前进（速度35，持续2.3秒）
            Sleep(1.2),
            SpinAntiClockwise(speed=30),  # 再次降低旋转速度
            Sleep(1.15),  # 调整旋转时间
            Advance(speed=35),  # 再次前进（速度35，持续2.3秒）
            Sleep(0.05),
            Stop(),
        ]
        
        
class Parking(ComplexAction):
    def __init__(self):
        super().__init__()
        self.action_seq = [
            Stop(),
            Sleep(1),

            CustomAction(motor_setting=[-85, 65, 60, -55]),
            Sleep(0.75),
            Stop(),

            Sleep(2),
            CustomAction(motor_setting=[65, -58, -55, 55]),
            Sleep(1),
            Stop()
        ]